1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642 |
- function varargout = PreprocMRI(varargin)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Reads MRI data into Fieldtrip and runs preprocessing. %
- % See: "help ft_read_mri" for supported filetypes. %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Copyright (C) 2013-2014, Michael J. Cheung
- %
- % This file is a part of the MEG & PLS Pipeline (MEGPLS). For more
- % details, see the documentation included with the software package.
- %
- % MEGPLS is free software: you can redistribute it and/or modify it under
- % the terms of the GNU General Public License version 2 as published by
- % the Free Software Foundation. This program is distributed in the hope
- % that it will be useful, but WITHOUT ANY WARRANTY; without even the
- % implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- % See the GNU General Public License for more details.
- %
- % You should have received a copy of the GNU General Public License along
- % with this program. If not, you can download the license here:
- % <http://www.gnu.org/licenses/old-licenses/gpl-2.0>.
- % Last Modified by GUIDE v2.5 21-Aug-2014 12:07:40
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @PreprocMRI_OpeningFcn, ...
- 'gui_OutputFcn', @PreprocMRI_OutputFcn, ...
- 'gui_LayoutFcn', [] , ...
- 'gui_Callback', []);
- if nargin && ischar(varargin{1})
- gui_State.gui_Callback = str2func(varargin{1});
- end
- if nargout
- [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
- else
- gui_mainfcn(gui_State, varargin{:});
- end
- % End initialization code - DO NOT EDIT
- %--- Executes just before PreprocMRI is made visible. ---%
- %--------------------------------------------------------%
- function PreprocMRI_OpeningFcn(hObject, eventdata, handles, varargin)
- % This function has no output args, see OutputFcn.
- % hObject handle to figure
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % varargin command line arguments to PreprocMRI (see VARARGIN)
- % Choose default command line output for PreprocMRI
- handles.output = hObject;
- % Update handles structure
- guidata(hObject, handles);
- % Make sure toolbox paths are added:
- [PipelineDir, ~, ~] = fileparts(which('PreprocMRI.m'));
- addpath(genpath(PipelineDir));
- rmpath([PipelineDir,'/DEFAULT_SETTINGS']); % Make sure its calling from AnalysisID
- rmpath([PipelineDir,'/TEMPORARY_FIXES']); % Make sure its calling from FT toolbox
- CheckToolboxPaths(PipelineDir);
- if exist('ErrorLog_PreprocMRI.txt', 'file')
- delete('ErrorLog_PreprocMRI.txt');
- end
- % Initialize variables:
- handles.paths.Rootpath = [];
- handles.paths.AnatID = [];
- handles.name.AnatID = [];
- handles.paths.CurrentGroupID = [];
- handles.name.CurrentGroupID = [];
- handles.name.SubjID = [];
- handles.gui.Status = [];
- handles.paths.AnatFolder = [];
- handles.paths.AnatFile = [];
- handles.paths.AnatFullpath = [];
- handles.paths.PreprocMRI = [];
- handles.FTcfg = [];
- handles.gui.ShowInstruct = 1;
- % Save handles:
- guidata(hObject, handles);
- % UIWAIT makes PreprocMRI wait for user response (see UIRESUME)
- % uiwait(handles.figure1);
- %--- Outputs from this function are returned to the command line. ---%
- %--------------------------------------------------------------------%
- function varargout = PreprocMRI_OutputFcn(hObject, eventdata, handles)
- % varargout cell array for returning output args (see VARARGOUT);
- % hObject handle to figure
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Get default command line output from handles structure
- varargout{1} = handles.output;
- %===================================%
- % FUNCTIONS FOR SELECTING ROOTPATH: %
- %===================================%
- %--- Executes on button press in ButtonSetRootpath. ---%
- %------------------------------------------------------%
- function ButtonSetRootpath_Callback(hObject, eventdata, handles)
- if ~isempty(handles.name.AnatID)
- prompt = {'WARNING:';
- 'Changing root directory will clear all current settings.'; '';
- 'Do you wish to continue?'};
-
- ChangeDir = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
- if strcmp(ChangeDir, 'NO')
- return;
- end
- end
- % Select and set rootpath:
- SelectedPath = uigetdir;
- if SelectedPath == 0
- return; % If user cancels
- end
- % Check if selected path has spaces (AFNI functions cannot read spaces):
- CheckSpaces = strfind(SelectedPath, ' ');
- if ~isempty(CheckSpaces)
- message = {'Error: Target directory selected contains spaces.';
- 'AFNI functions cannot read folder & file paths with spaces.';
- 'AFNI functions are required for file conversions later on.'};
- msgbox(message, 'Error:')
- return;
- end
- handles.paths.Rootpath = SelectedPath;
- set(handles.TextboxRootpath, 'String', handles.paths.Rootpath);
- % Start Waitbox:
- WaitBox = StartWaitBox('SETTING TARGET DIRECTORY:');
- % Reset AnatID:
- handles.name.AnatID = [];
- handles.paths.AnatID = [];
- set(handles.TextboxAnatID, 'String', 'None Selected');
- % Reset GroupID:
- handles.name.CurrentGroupID = [];
- handles.paths.CurrentGroupID = [];
- set(handles.TextboxGroupID, 'String', 'None Selected');
- % Reset settings & GUI panels:
- handles = ResetSubjIDSettings (handles);
- handles = ResetInputAnatSettings (handles);
- handles = ResetStatusSettings (handles);
- handles = ResetPreprocSettings (handles);
- % Update settings & GUI panels (to enable/disable):
- handles = UpdateSubjIDSettings (handles);
- handles = UpdateInputAnatSettings (handles);
- handles = UpdateStatusSettings (handles);
- handles = UpdatePreprocSettings (handles);
- % Save handles:
- guidata(hObject, handles);
- close(WaitBox);
- %--- Textbox to display selected Rootpath: ---%
- %---------------------------------------------%
- function TextboxRootpath_Callback(hObject, eventdata, handles)
- EnteredText = get(handles.TextboxRootpath, 'String');
- if ~isequal(EnteredText, handles.paths.Rootpath)
- set(handles.TextboxRootpath, 'String', handles.paths.Rootpath);
- msgbox('Note: Use button to change Rootpath.')
- end
- %===========================================%
- % FUNCTIONS FOR CREATING OR LOADING ANATID: %
- %===========================================%
- %--- Executes on button press in ButtonCreateAnatID. ---%
- %-------------------------------------------------------%
- function ButtonCreateAnatID_Callback(hObject, eventdata, handles)
- if isempty(handles.paths.Rootpath)
- msgbox('Warning: Select root directory first.', 'Warning:');
- return;
- end
- % Enter name of AnatID:
- UserInput = inputdlg('Enter AnatID name:', 'Create new AnatID:');
- UserInput = deblank(UserInput);
- UserInput = regexprep(UserInput, '\s+', '_');
- if isempty(char(UserInput))
- return; % If user cancels
- end
- PathInputID = [handles.paths.Rootpath,'/AnatID_',UserInput{1}];
- if exist(PathInputID, 'dir')
- msgbox('Error: Specified AnatID already exists!', 'Error:')
- return;
- end
- % Set AnatID & create folder:
- status = mkdir(PathInputID);
- if status == 1 % If mkdir successful
- handles.name.AnatID = UserInput{1};
- handles.paths.AnatID = PathInputID;
- set(handles.TextboxAnatID, 'String', handles.name.AnatID);
- else
- msgbox('Error: Failed to create AnatID folder.', 'Error:')
- return;
- end
- % Start Waitbox:
- WaitBox = StartWaitBox('CREATING ANAT ID:');
- % Reset GroupID:
- handles.name.CurrentGroupID = [];
- handles.paths.CurrentGroupID = [];
- set(handles.TextboxGroupID, 'String', []);
- % Reset settings & GUI panels:
- handles = ResetSubjIDSettings (handles);
- handles = ResetInputAnatSettings (handles);
- handles = ResetStatusSettings (handles);
- handles = ResetPreprocSettings (handles);
- % Update settings & GUI panels (to enable/disable):
- handles = UpdateSubjIDSettings (handles);
- handles = UpdateInputAnatSettings (handles);
- handles = UpdateStatusSettings (handles);
- handles = UpdatePreprocSettings (handles);
- % Save handles:
- guidata(hObject, handles);
- close(WaitBox);
- %--- Executes on button press in ButtonLoadAnatID. ---%
- %-----------------------------------------------------%
- function ButtonLoadAnatID_Callback(hObject, eventdata, handles)
- if isempty(handles.paths.Rootpath)
- msgbox('Warning: Select root directory first.', 'Warning:');
- return;
- end
- % Get AnatID folders in current rootpath:
- DetectedFolders = dir([handles.paths.Rootpath,'/AnatID_*']);
- RemoveIndex = [];
- for d = 1:length(DetectedFolders)
- if DetectedFolders(d).isdir ~= 1
- RemoveIndex = [RemoveIndex, d]; % Get unwanted indices
- end
- end
- DetectedFolders(RemoveIndex) = [];
- if isempty(DetectedFolders)
- msgbox('Error: No AnatID folders detected inside root dir.', 'Error:');
- return;
- end
- % List AnatID folders for selection:
- DetectedFolders = {DetectedFolders.name};
- SelectedIndex = listdlg('PromptString', 'Select AnatID to load:',...
- 'ListSize', [300, 300], 'SelectionMode', 'single', 'ListString', DetectedFolders);
- if isempty(SelectedIndex)
- return; % If user cancels.
- end
- SelectedAnatID = DetectedFolders{SelectedIndex};
- SelectedAnatID(1:7) = []; % Remove "AnatID_" prefix to get AnatID suffix.
- FullpathAnatID = [handles.paths.Rootpath,'/AnatID_',SelectedAnatID];
- % Set as current AnatID:
- handles.name.AnatID = SelectedAnatID;
- handles.paths.AnatID = FullpathAnatID;
- set(handles.TextboxAnatID, 'String', handles.name.AnatID);
- % Start Waitbox:
- WaitBox = StartWaitBox('LOADING ANAT ID:');
- % Reset GroupID:
- handles.name.CurrentGroupID = [];
- handles.paths.CurrentGroupID = [];
- set(handles.TextboxGroupID, 'String', []);
- % Reset settings & GUI panels:
- handles = ResetSubjIDSettings (handles);
- handles = ResetInputAnatSettings (handles);
- handles = ResetStatusSettings (handles);
- handles = ResetPreprocSettings (handles);
- % Update settings & GUI panels (to enable/disable):
- handles = UpdateSubjIDSettings (handles);
- handles = UpdateInputAnatSettings (handles);
- handles = UpdateStatusSettings (handles);
- handles = UpdatePreprocSettings (handles);
- % Save handles:
- guidata(hObject, handles);
- close(WaitBox);
- %--- Textbox to display current AnatID: ---%
- %------------------------------------------%
- function TextboxAnatID_Callback(hObject, eventdata, handles)
- EnteredText = get(handles.TextboxAnatID, 'String');
- if ~isequal(EnteredText, handles.name.AnatID)
- set(handles.TextboxAnatID, 'String', handles.name.AnatID);
- msgbox('Note: Use button to change AnatID.')
- end
- %===========================================%
- % FNCTIONS FOR CREATING OR LOADING GROUPID: %
- %===========================================%
- %--- Executes on button press in ButtonCreateGroupID. ---%
- %--------------------------------------------------------%
- function ButtonCreateGroupID_Callback(hObject, eventdata, handles)
- if isempty(handles.paths.Rootpath)
- msgbox('Warning: Select root directory first.', 'Warning:');
- return;
- end
- if isempty(handles.name.AnatID) || isempty(handles.paths.AnatID)
- msgbox('Warning: Create or load AnatID first.', 'Warning:');
- return;
- end
- % Enter name of GroupID:
- UserInput = inputdlg('Enter GroupID name:', 'Create new GroupID:');
- UserInput = deblank(UserInput);
- UserInput = regexprep(UserInput, '\s+', '_');
- if isempty(char(UserInput))
- return; % If user cancels
- end
- PathInputID = [handles.paths.AnatID,'/GroupID_',UserInput{1}];
- if exist(PathInputID, 'dir')
- msgbox('Error: Specified GroupID already exists for this AnatID.', 'Error:')
- return;
- end
- % Set GroupID and create folder:
- status = mkdir(PathInputID);
- if status == 1 % If mkdir successful
- handles.name.CurrentGroupID = UserInput{1};
- handles.paths.CurrentGroupID = PathInputID;
- set(handles.TextboxGroupID, 'String', handles.name.CurrentGroupID);
- else
- msgbox('Error: Failed to create GroupID folder.', 'Error:')
- return;
- end
- % Start Waitbox:
- WaitBox = StartWaitBox('CREATING GROUP ID:');
- % Reset settings & GUI panels:
- handles = ResetSubjIDSettings (handles);
- handles = ResetInputAnatSettings (handles);
- handles = ResetStatusSettings (handles);
- handles = ResetPreprocSettings (handles);
- % Update settings & GUI panels (to enable/disable):
- handles = UpdateSubjIDSettings (handles);
- handles = UpdateInputAnatSettings (handles);
- handles = UpdateStatusSettings (handles);
- handles = UpdatePreprocSettings (handles);
- % Save handles:
- guidata(hObject, handles);
- close(WaitBox);
- %--- Executes on button press in ButtonLoadGroupID. ---%
- %------------------------------------------------------%
- function ButtonLoadGroupID_Callback(hObject, eventdata, handles)
- if isempty(handles.paths.Rootpath)
- msgbox('Warning: Select root directory first.', 'Warning:');
- return;
- end
- if isempty(handles.name.AnatID) || isempty(handles.paths.AnatID)
- msgbox('Warning: Create or load AnatID first.', 'Warning:');
- return;
- end
- % Acquire GroupID folders for current AnatID:
- DetectedFolders = dir([handles.paths.AnatID,'/GroupID_*']);
- RemoveIndex = [];
- for g = 1:length(DetectedFolders)
- if DetectedFolders(g).isdir ~= 1
- RemoveIndex = [RemoveIndex, g]; % Get unwanted indices
- end
- end
- DetectedFolders(RemoveIndex) = [];
- if isempty(DetectedFolders)
- msgbox('Error: No GroupID folders were detected for current AnatID.', 'Error:');
- return;
- end
- % List detected GroupID folders for selection:
- DetectedFolders = {DetectedFolders.name};
- SelectedIndex = listdlg('PromptString', 'Select GroupID to load:',...
- 'ListSize', [300, 300], 'SelectionMode', 'single', 'ListString', DetectedFolders);
- if isempty(SelectedIndex)
- return; % If user cancels
- end
- SelectedGroupID = DetectedFolders{SelectedIndex};
- SelectedGroupID(1:8) = []; % Remove "GroupID_" prefix to get GroupID.
- % Set as current GroupID:
- handles.name.CurrentGroupID = SelectedGroupID;
- handles.paths.CurrentGroupID = [handles.paths.AnatID,'/GroupID_',SelectedGroupID];
- set(handles.TextboxGroupID, 'String', handles.name.CurrentGroupID);
- % Start Waitbox:
- WaitBox = StartWaitBox('LOADING GROUP ID:');
- % Reset settings & GUI panels:
- handles = ResetSubjIDSettings (handles);
- handles = ResetInputAnatSettings (handles);
- handles = ResetStatusSettings (handles);
- handles = ResetPreprocSettings (handles);
- % Load PreprocInputMRI .mat for GroupID if available:
- PreprocInputMat = [handles.paths.CurrentGroupID,...
- '/PreprocInputMRI_',handles.name.CurrentGroupID,'.mat'];
- if exist(PreprocInputMat, 'file')
- LoadedMat = load(PreprocInputMat);
- handles = LoadSubjIDSettings (handles, LoadedMat);
- handles = LoadInputAnatSettings (handles, LoadedMat);
- else
- message = {'WARNING:';
- 'PreprocInputMRI .mat file not found for GroupID.';
- 'SubjIDs and input MRI files will need to be selected again.'};
- msgbox(message, 'Warning:');
- end
- % Update settings & GUI panels (to enable/disable):
- handles = UpdateSubjIDSettings (handles);
- handles = UpdateInputAnatSettings (handles);
- handles = UpdatePreprocSettings (handles);
- % Update status for all loaded subjects:
- StatusWaitbar = waitbar(0, ...
- 'Please wait. Loading files from session.', 'Windowstyle', 'modal');
- for s = 1:length(handles.name.SubjID)
- waitbar(s/length(handles.name.SubjID), StatusWaitbar);
- handles = DetectStatus(handles, s);
- end
- delete(StatusWaitbar)
- handles = UpdateStatusSettings(handles);
- % Save handles:
- guidata(hObject, handles);
- close(WaitBox);
- %--- Textbox to display current GroupID: ---%
- %-------------------------------------------%
- function TextboxGroupID_Callback(hObject, eventdata, handles)
- EnteredText = get(handles.TextboxGroupID, 'String');
- if ~isequal(EnteredText, handles.name.CurrentGroupID)
- set(handles.TextboxGroupID, 'String', handles.name.CurrentGroupID);
- msgbox('Note: Use button to change GroupID.')
- end
- %============================================%
- % FUNCTIONS FOR ADDING OR REMOVING SUBJECTS: %
- %============================================%
- %--- Executes on selection change in ListboxSubjID. ---%
- %------------------------------------------------------%
- function ListboxSubjID_Callback(hObject, eventdata, handles)
- SelectedIndex = get(handles.ListboxSubjID, 'Value');
- set(handles.ListboxInputAnat, 'Value', SelectedIndex);
- set(handles.ListboxStatus, 'Value', SelectedIndex);
- handles = UpdatePreprocSettings(handles); % For enable/disable
- guidata(hObject, handles);
- %--- User enters SubjID into textbox. ---%
- %----------------------------------------%
- function TextboxSubjID_Callback(hObject, eventdata, handles)
- keypress = get(gcf, 'CurrentCharacter');
- if isequal(keypress, char(13))
- ButtonAddSubjID_Callback(hObject, eventdata, handles);
- end
- %--- Executes on button press in ButtonAddSubjID. ---%
- %----------------------------------------------------%
- function ButtonAddSubjID_Callback(hObject, eventdata, handles)
- if isempty(handles.name.AnatID) || isempty(handles.paths.AnatID)
- msgbox('Warning: Create or load AnatID first.', 'Warning:');
- return;
- end
- if isempty(handles.name.CurrentGroupID)
- msgbox('Warning: Create or load GroupID first.', 'Warning:');
- return;
- end
- % Reads and set SubjID:
- InputSubjID = get(handles.TextboxSubjID, 'String');
- InputSubjID = deblank(InputSubjID);
- InputSubjID = regexprep(InputSubjID, '\s+', '_');
- InputSubjID = cellstr(InputSubjID);
- if isempty(InputSubjID{1})
- return;
- end
- if ~isempty(handles.name.SubjID) && ismember(InputSubjID{1}, handles.name.SubjID)
- return; % If SubjID already added
- end
- handles.name.SubjID = [handles.name.SubjID; InputSubjID];
- NewIndex = length(handles.name.SubjID);
- % Initialize cells for new subject:
- handles.paths.AnatFolder {NewIndex} = [];
- handles.paths.AnatFile {NewIndex} = [];
- handles.paths.AnatFullpath {NewIndex} = [];
- handles.paths.PreprocMRI {NewIndex} = [];
- handles.gui.Status {NewIndex} = [];
- % Update GUI:
- handles = UpdateSubjIDSettings (handles);
- handles = UpdateInputAnatSettings (handles);
- handles = DetectStatus (handles, NewIndex);
- handles = UpdateStatusSettings (handles);
- handles = UpdatePreprocSettings (handles); % For enable/disable
- % Save handles:
- set(handles.ListboxSubjID, 'Value', length(handles.name.SubjID));
- if ~isempty(handles.paths.AnatFullpath)
- set(handles.ListboxInputAnat, 'Value', length(handles.name.SubjID));
- end
- if ~isempty(handles.gui.Status)
- set(handles.ListboxStatus, 'Value', length(handles.name.SubjID));
- end
- guidata(hObject, handles);
- %--- Executes on button press in ButtonRmvSubjID. ---%
- %----------------------------------------------------%
- function ButtonRmvSubjID_Callback(hObject, eventdata, handles)
- if isempty(handles.name.SubjID)
- return;
- end
- SelectedIndex = get(handles.ListboxSubjID, 'Value');
- handles.name.SubjID(SelectedIndex) = [];
- % Remove data & status cells for removed subject:
- handles.paths.AnatFolder (SelectedIndex) = [];
- handles.paths.AnatFile (SelectedIndex) = [];
- handles.paths.AnatFullpath (SelectedIndex) = [];
- handles.paths.PreprocMRI (SelectedIndex) = [];
- handles.gui.Status (SelectedIndex) = [];
- % Update GUI:
- handles = UpdateSubjIDSettings (handles);
- handles = UpdateInputAnatSettings (handles);
- handles = UpdateStatusSettings (handles);
- handles = UpdatePreprocSettings (handles); % For enable/disable
- % Save handles:
- guidata(hObject, handles);
- %--- Updates SubjID settings & GUI panel: ---%
- %--------------------------------------------%
- function OutputHandles = UpdateSubjIDSettings(InputHandles)
- handles = InputHandles;
- % Update PreprocMRI paths (Location of FT MRIs to be read in):
- for s = 1:length(handles.name.SubjID)
- handles.paths.PreprocMRI{s} = ...
- [handles.paths.CurrentGroupID,'/',handles.name.SubjID{s},'_PreprocMRI.mat'];
- end
- % Update listbox:
- set(handles.ListboxSubjID, 'String', handles.name.SubjID);
- CurrentIndex = get(handles.ListboxSubjID, 'Value');
- MaxSubjIndex = length(handles.name.SubjID);
- if isempty(CurrentIndex) || CurrentIndex == 0 || CurrentIndex > MaxSubjIndex
- set(handles.ListboxSubjID, 'Value', MaxSubjIndex);
- set(handles.ListboxInputAnat, 'Value', MaxSubjIndex);
- set(handles.ListboxStatus, 'Value', MaxSubjIndex);
- end
- % Set output handles:
- OutputHandles = handles;
- %--- Load SubjID settings & GUI panel: ---%
- %-----------------------------------------%
- function OutputHandles = LoadSubjIDSettings(InputHandles, LoadedMat)
- handles = InputHandles;
- % Load SubjID and respective PreprocMRI paths:
- handles.name.SubjID = LoadedMat.name.SubjID;
- handles.paths.PreprocMRI = LoadedMat.paths.PreprocMRI;
- % Load GUI:
- set(handles.ListboxSubjID, 'String', handles.name.SubjID);
- set(handles.ListboxSubjID, 'Value', 1);
- handles = UpdatePreprocSettings(handles); % For enable/disable
- % Set output handles:
- OutputHandles = handles;
- %--- Reset SubjID settings & GUI panel: ---%
- %------------------------------------------%
- function OutputHandles = ResetSubjIDSettings(InputHandles)
- handles = InputHandles;
- handles.paths.PreprocMRI = [];
- handles.name.SubjID = [];
- set(handles.ListboxSubjID, 'String', []);
- set(handles.ListboxSubjID, 'Value', 1);
- % Set output handles:
- OutputHandles = handles;
- %=============================================%
- % FUNCTIONS FOR MRI FILE SELECTION & DISPLAY: %
- %=============================================%
- %--- Executes on selection change in ListboxInputAnat. ---%
- %---------------------------------------------------------%
- function ListboxInputAnat_Callback(hObject, eventdata, handles)
- SelectedIndex = get(handles.ListboxInputAnat, 'Value');
- set(handles.ListboxSubjID, 'Value', SelectedIndex);
- set(handles.ListboxStatus, 'Value', SelectedIndex);
- handles = UpdatePreprocSettings(handles); % For enable/disable
- guidata(hObject, handles);
- %--- Updates settings & GUI panel for input MRI files: ---%
- %---------------------------------------------------------%
- function OutputHandles = UpdateInputAnatSettings(InputHandles)
- handles = InputHandles;
- % Make sure cells initialized:
- for s = 1:length(handles.name.SubjID)
- try
- handles.paths.AnatFolder{s};
- handles.paths.AnatFile{s};
- handles.paths.AnatFullpath{s};
- catch
- handles.paths.AnatFolder{s} = [];
- handles.paths.AnatFile{s} = [];
- handles.paths.AnatFullpath{s} = [];
- end
- end
- % Update listbox:
- set(handles.ListboxInputAnat, 'String', handles.paths.AnatFullpath);
- % Set output handles:
- OutputHandles = handles;
- %--- Load settings & GUI panel for input MRI files: ---%
- %------------------------------------------------------%
- function OutputHandles = LoadInputAnatSettings(InputHandles, LoadedMat)
- handles = InputHandles;
- % Load input MRI files:
- handles.paths.AnatFolder = LoadedMat.paths.AnatFolder;
- handles.paths.AnatFile = LoadedMat.paths.AnatFile;
- handles.paths.AnatFullpath = LoadedMat.paths.AnatFullpath;
- % Update GUI:
- set(handles.ListboxInputAnat, 'String', handles.paths.AnatFullpath);
- set(handles.ListboxInputAnat, 'Value', 1);
- handles = UpdatePreprocSettings(handles); % For enable/disable
- % Set output handles:
- OutputHandles = handles;
- %--- Reset settings & GUI panel for input MRI files: ---%
- %-------------------------------------------------------%
- function OutputHandles = ResetInputAnatSettings(InputHandles)
- handles = InputHandles;
- % Reset input anat:
- handles.paths.AnatFolder = [];
- handles.paths.AnatFile = [];
- handles.paths.AnatFullpath = [];
- for s = 1:length(handles.name.SubjID)
- handles.paths.AnatFolder{s} = [];
- handles.paths.AnatFile{s} = [];
- handles.paths.AnatFullpath{s} = [];
- end
- % Reset GUI panel:
- set(handles.ListboxInputAnat, 'String', []);
- set(handles.ListboxInputAnat, 'Value', 1);
- % Set output handles:
- OutputHandles = handles;
- %===============================%
- % FUNCTIONS FOR STATUS UPDATES: %
- %===============================%
- %--- Executes on selection change in ListboxStatus. ---%
- %------------------------------------------------------%
- function ListboxStatus_Callback(hObject, eventdata, handles)
- SelectedIndex = get(handles.ListboxStatus, 'Value');
- set(handles.ListboxSubjID, 'Value', SelectedIndex);
- set(handles.ListboxInputAnat, 'Value', SelectedIndex);
- handles = UpdatePreprocSettings(handles); % For enable/disable
- guidata(hObject, handles);
- %--- Executes on button press in ButtonRefreshStatus. ---%
- %--------------------------------------------------------%
- function ButtonRefreshStatus_Callback(hObject, eventdata, handles)
- StatusWaitbar = waitbar(0, ...
- 'Please wait. Loading files from session.', 'Windowstyle', 'modal');
- for s = 1:length(handles.name.SubjID)
- waitbar(s/length(handles.name.SubjID), StatusWaitbar);
- handles = DetectStatus(handles, s);
- end
- delete(StatusWaitbar)
- handles = UpdateStatusSettings(handles);
- guidata(hObject, handles);
- %--- Function to acquire status: ---%
- %-----------------------------------%
- function OutputHandles = DetectStatus(InputHandles, SubjIndex)
- handles = InputHandles;
- % Get selected subject and update status.
- % Unlike PreprocMEG, only selected subject gets worked on, so
- % update on a subject-by-subject basis for efficiency.
- s = SubjIndex;
- % Check if MRI file has been selected:
- if isempty(handles.paths.AnatFullpath{s})
- handles.gui.Status{s} = 'Select MRI file to load into FT.';
- else
- handles.gui.Status{s} = [];
- end
- % Check if read into FT and coregistration:
- if exist(handles.paths.PreprocMRI{s}, 'file')
- MRIdata = LoadFTmat(handles.paths.PreprocMRI{s}, 'PreprocMRI');
-
- if isempty(MRIdata)
- handles.gui.Status{s} = 'FT file detected, but could not be read. See ErrorLog.';
-
- else
- DimStr = num2str(MRIdata.dim);
- if isfield(MRIdata, 'coordsys')
- Coordsys = num2str(MRIdata.coordsys);
- handles.gui.Status{s} = ...
- ['FT file detected. Coordsys: ',Coordsys,'. Dims: ',DimStr];
- else
- handles.gui.Status{s} = ...
- ['FT file detected. No Coordsys found. Dims: ',DimStr];
- end
- end
- end
- % Save as output:
- OutputHandles = handles;
- %--- Update status settings & GUI panel: ---%
- %-------------------------------------------%
- function OutputHandles = UpdateStatusSettings(InputHandles)
- handles = InputHandles;
- % Make sure cells initialized:
- for s = 1:length(handles.name.SubjID)
- try
- handles.gui.Status{s};
- catch
- handles.gui.Status{s} = [];
- end
- end
- % Update listbox:
- set(handles.ListboxStatus, 'String', handles.gui.Status);
- % Set output handles:
- OutputHandles = handles;
- %--- Reset status settings & GUI panel: ---%
- %------------------------------------------%
- function OutputHandles = ResetStatusSettings(InputHandles)
- handles = InputHandles;
- % Reset status:
- handles.gui.Status = [];
- for s = 1:length(handles.name.SubjID)
- handles.gui.Status{s} = [];
- end
- % Reset GUI status panel:
- set(handles.ListboxStatus, 'String', []);
- set(handles.ListboxStatus, 'Value', 1);
- % Set output handles:
- OutputHandles = handles;
- %===============================================%
- % FUNCTIONS FOR SAVING & LOADING PREPROC INPUT: %
- %===============================================%
- %--- Executes on button press in ButtonSaveInput. ---%
- %----------------------------------------------------%
- function ButtonSaveInput_Callback(hObject, eventdata, handles)
- if isempty(handles.paths.Rootpath)
- msgbox('Warning: Select root directory first.', 'Warning:');
- return;
- end
- if isempty(handles.name.AnatID) || isempty(handles.paths.AnatID)
- msgbox('Warning: Create or load AnatID first.', 'Warning:');
- return;
- end
- if isempty(handles.name.CurrentGroupID)
- msgbox('Warning: Create or load GroupID first.', 'Warning:');
- return;
- end
- if isempty(handles.name.SubjID) || isempty(handles.paths.PreprocMRI)
- msgbox('Warning: Need to specify SubjIDs.', 'Warning:');
- return;
- end
- if isempty(handles.paths.AnatFullpath)
- msgbox('Warning: MRI files have not been read into FT yet.', 'Warning:')
- return;
- end
- % Make sure Rootpath & AnatID don't have spaces (will cause issues for AFNI later):
- CheckSpaces1 = strfind(handles.paths.Rootpath, ' ');
- CheckSpaces2 = strfind(handles.paths.AnatID, ' ');
- if ~isempty(CheckSpaces1) || ~isempty(CheckSpaces2)
- message = {'Error: Target directory or AnatID contains spaces.';
- 'AFNI functions cannot read folder & file paths with spaces.';
- 'AFNI functions are required for file conversions later on.'};
- msgbox(message, 'Error:')
- return;
- end
- % Check save path:
- PreprocInputMat = [handles.paths.CurrentGroupID,...
- '/PreprocInputMRI_',handles.name.CurrentGroupID,'.mat'];
- if exist(PreprocInputMat, 'file')
- prompt = {'WARNING:';
- 'PreprocInputMRI .mat already exists for this GroupID.';
- 'Do you wish to continue and overwrite it?'};
-
- OverwriteMat = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
- if strcmp(OverwriteMat, 'NO')
- return;
- else
- delete(PreprocInputMat);
- end
- end
- % Save input parameters for current GroupID:
- name = handles.name;
- paths = handles.paths;
- paths = rmfield(paths, 'Rootpath'); % Rmv GUI only paths that aren't in load fcns.
- paths = rmfield(paths, 'AnatID'); % - These paths auto-adapt if folders moved.
- paths = rmfield(paths, 'CurrentGroupID');
- CheckSavePath(PreprocInputMat, 'PreprocMRI');
- save(PreprocInputMat, 'name', 'paths');
- % Feedback:
- if exist(PreprocInputMat, 'file')
- msgbox('Current input parameters successfully saved.')
- else
- msgbox('Error: Failed to save input parameters.')
- end
- %--- Executes on button press in ButtonLoadInput. ---%
- %----------------------------------------------------%
- function ButtonLoadInput_Callback(hObject, eventdata, handles)
- if isempty(handles.paths.Rootpath)
- msgbox('Warning: Select root directory first.', 'Warning:');
- return;
- end
- if isempty(handles.name.AnatID) || isempty(handles.paths.AnatID)
- msgbox('Warning: Create or load AnatID first.', 'Warning:');
- return;
- end
- if isempty(handles.name.CurrentGroupID)
- msgbox('Warning: Create or load GroupID first.', 'Warning:');
- return;
- end
- [matfile, matpath] = uigetfile([handles.paths.CurrentGroupID,...
- '/PreprocInputMRI_*.mat'], 'Select PreprocInputMRI .mat:', 'MultiSelect', 'off');
- if matfile == 0
- msgbox('Note: Load cancelled. File not selected.', 'Note:');
- return;
- end
- % Reset settings & GUI panels:
- handles = ResetSubjIDSettings (handles);
- handles = ResetInputAnatSettings (handles);
- handles = ResetStatusSettings (handles);
- handles = ResetPreprocSettings (handles);
- % Load input settings:
- LoadedMat = load([matpath,matfile]);
- handles = LoadSubjIDSettings (handles, LoadedMat);
- handles = LoadInputAnatSettings (handles, LoadedMat);
- % Update settings & GUI panels (to enable/disable):
- handles = UpdateSubjIDSettings (handles);
- handles = UpdateInputAnatSettings (handles);
- handles = UpdatePreprocSettings (handles);
- % Update status for all loaded subjects:
- StatusWaitbar = waitbar(0, ...
- 'Please wait. Loading files from session.', 'Windowstyle', 'modal');
- for s = 1:length(handles.name.SubjID)
- waitbar(s/length(handles.name.SubjID), StatusWaitbar);
- handles = DetectStatus(handles, s);
- end
- delete(StatusWaitbar)
- handles = UpdateStatusSettings(handles);
- % Save handles:
- guidata(hObject, handles);
- %======================================%
- % FUNCTIONS TO READ IN & PROCESS MRIs: %
- %======================================%
- %--- Executes on button press in ButtonReadMRItoFT. ---%
- %------------------------------------------------------%
- function ButtonReadMRItoFT_Callback(hObject, eventdata, handles)
- if isempty(handles.name.AnatID) || isempty(handles.paths.AnatID)
- msgbox('Warning: Create or load AnatID first.', 'Warning:');
- return;
- end
- if isempty(handles.name.CurrentGroupID)
- msgbox('Warning: Create or load GroupID first.', 'Warning:');
- return;
- end
- if isempty(handles.name.SubjID)
- msgbox('Warning: Add SubjID first.', 'Warning:');
- return;
- end
- % Make sure Rootpath & AnatID don't have spaces (will cause issues for AFNI later):
- CheckSpaces1 = strfind(handles.paths.Rootpath, ' ');
- CheckSpaces2 = strfind(handles.paths.AnatID, ' ');
- if ~isempty(CheckSpaces1) || ~isempty(CheckSpaces2)
- message = {'Error: Target directory or AnatID contains spaces.';
- 'AFNI functions cannot read folder & file paths with spaces.';
- 'AFNI functions are required for file conversions later on.'};
- msgbox(message, 'Error:')
- return;
- end
- % Check for existing files:
- SubjIndex = get(handles.ListboxSubjID, 'Value');
- if exist(handles.paths.PreprocMRI{SubjIndex}, 'file')
- prompt = {'Warning: PreprocMRI already exists for this SubjID.';
- 'Do you wish to continue and overwrite?'};
-
- Overwrite = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
- if strcmp(Overwrite, 'NO')
- return;
- end
- end
- % Select raw MRI file and read into FT:
- [File, Folder] = uigetfile([handles.paths.Rootpath,'/*']);
- if File == 0
- return; % If user cancels
- end
- WaitBox = StartWaitBox('READING MRI FILE INTO FT:');
- MRIdata = ft_read_mri([Folder,File])
- close(WaitBox);
- CheckSavePath(handles.paths.PreprocMRI{SubjIndex}, 'PreprocMRI');
- save(handles.paths.PreprocMRI{SubjIndex}, 'MRIdata');
- handles.paths.AnatFolder {SubjIndex} = Folder;
- handles.paths.AnatFile {SubjIndex} = File;
- handles.paths.AnatFullpath {SubjIndex} = [Folder,File];
- % Update GUI:
- handles = UpdateInputAnatSettings (handles);
- handles = UpdatePreprocSettings (handles);
- handles = DetectStatus (handles, SubjIndex);
- handles = UpdateStatusSettings (handles);
- % Save handles:
- guidata(hObject, handles);
- %--- Executes on button press in ButtonClearMRI. ---%
- %---------------------------------------------------%
- function ButtonClearMRI_Callback(hObject, eventdata, handles)
- if isempty(handles.name.SubjID)
- return;
- end
- % Remove FT MRI file for selected SubjID:
- SubjIndex = get(handles.ListboxSubjID, 'Value');
- if exist(handles.paths.PreprocMRI{SubjIndex}, 'file')
- delete(handles.paths.PreprocMRI{SubjIndex});
- end
- if ~isempty(handles.paths.AnatFullpath)
- handles.paths.AnatFolder {SubjIndex} = [];
- handles.paths.AnatFile {SubjIndex} = [];
- handles.paths.AnatFullpath {SubjIndex} = [];
- end
- % Update GUI:
- handles = UpdateInputAnatSettings (handles);
- handles = UpdatePreprocSettings (handles);
- handles = DetectStatus (handles, SubjIndex);
- handles = UpdateStatusSettings (handles);
- % Save handles:
- guidata(hObject, handles);
- %--- Executes on button press in ButtonCheckTransformHand. ---%
- %-------------------------------------------------------------%
- function ButtonCheckTransformHand_Callback(hObject, eventdata, handles)
- if isempty(handles.name.SubjID) || isempty(handles.paths.PreprocMRI)
- msgbox('Warning: Add and select SubjID first.', 'Warning:')
- return;
- end
- % Load MRI file:
- SubjIndex = get(handles.ListboxSubjID, 'Value');
- if ~exist(handles.paths.PreprocMRI{SubjIndex}, 'file')
- msgbox('Warning: MRI file for SubjID has not been read into FT yet.', 'Warning:')
- return;
- end
- MRIdata = LoadFTmat(handles.paths.PreprocMRI{SubjIndex}, 'PreprocMRI');
- if isempty(MRIdata)
- msgbox('Error: Failed to load PreprocMRI file for SubjID. See ErrorLog.', 'Error:')
- return;
- end
- % Check handedness of transformation matrix:
- temp = det(MRIdata.transform(1:3, 1:3));
- if temp < 0
- message = {'Transformation matrix is left-handed.';
- 'If +XYZ is also right-handed, viewer shows radiological view.'};
- msgbox(message);
- else
- message = {'Transformation matrix is right-handed.';
- 'If +XYZ is also right-handed, viewer shows neurological view.'};
- msgbox(message);
- end
- %--- Executes on selection change in DropdownCoordsys. ---%
- %---------------------------------------------------------%
- function DropdownCoordsys_Callback(hObject, eventdata, handles)
- % Note: By default, if cfg.coordsys is not specified for ft_volumerealign,
- % the output coordinate system will always default to "ctf" or "spm".
- % User specifies desired coordinate system here to fill in cfg.coordsys field.
- guidata(hObject, handles);
- %--- Executes on button press in ButtonCoregisterMRI. ---%
- %--------------------------------------------------------%
- function ButtonCoregisterMRI_Callback(hObject, eventdata, handles)
- if isempty(handles.name.SubjID) || isempty(handles.paths.PreprocMRI)
- msgbox('Warning: Add and select SubjID first.', 'Warning:')
- return;
- end
- % Load MRI file:
- SubjIndex = get(handles.ListboxSubjID, 'Value');
- if ~exist(handles.paths.PreprocMRI{SubjIndex}, 'file')
- msgbox('Warning: MRI file for SubjID has not been read into FT yet.', 'Warning:')
- return;
- end
- MRIdata = LoadFTmat(handles.paths.PreprocMRI{SubjIndex}, 'PreprocMRI');
- if isempty(MRIdata)
- msgbox('Error: Failed to load PreprocMRI file for SubjID. See ErrorLog.', 'Error:')
- return;
- end
- % Check for coordsys (coregistration):
- if isfield(MRIdata, 'coordsys')
- prompt = {'WARNING:'; '';
- 'Field "coordsys" detected. MRI may already be coregistered.';
- 'If so, it is recommended you DO NOT coregister again.'; '';
- 'If you wish to redo the coregistration, go back and click the';
- '"Clear Subj FT MRI" button first.'; '';
- 'Do you wish to continue and run coregistration again?'; ''};
-
- RunCoreg = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
- if strcmp(RunCoreg, 'NO')
- return;
- end
- end
- % Show instructions:
- if handles.gui.ShowInstruct == 1;
- Instructions = {'----------------------------';
- 'COREGISTRATION INSTRUCTIONS:';
- '----------------------------'; '';
- 'NOTE:';
- 'If the crosshair does not appear, push "C" to toggle its visibility.'; ''; '';
- 'IMPORTANT:';
- ' Push "F" to toggle FIDUCIAL & LANDMARK visibility: When you place';
- ' fiducials and landmarks, they should appear as coloured circles.'; ''; '';
- 'If placing FIDUCIALS (ex: for CTF):';
- ' 1) Push "F" to toggle fiducial visibility if it is not on.';
- ' 2) Place fiducials with keys: "L" (left), "R" (right), and "N" (nasion).';
- ' 3) Set extra Z-point in positive Z-coordinates using "Z" (see below).';
- ' 4) Once finished, push "Q" to save the coregistration.'; '';
- ' In most cases, Z-point can normally be placed at the top-of-head.';
- ' Additional Z-point ensures left & right fiducials are not flipped.';
- ' Note: Only works with MRI formats supported by Fieldtrip.'; ''; '';
- 'If placing LANDMARKS (ex: for SPM):';
- ' 1) Place landmarks with keys: "A", "P", and "Z".';
- ' 2) Once finished, push "Q" to save the coregistration.'; ''; ''; ''};
-
- Show = questdlg(Instructions, 'INSTRUCTIONS:', 'OK', 'Don''t show again', 'OK');
- if strcmp(Show, 'Don''t show again')
- handles.gui.ShowInstruct = 0;
- end
- end
- % Get target coordinate system from coordsys dropdown:
- % Note: Defaults to "ctf" or "spm" if cfg.coordsys is left empty.
- DropdownOptions = get(handles.DropdownCoordsys, 'String');
- CoregCoordsys = DropdownOptions{get(handles.DropdownCoordsys, 'Value')};
- ViableOptions = {'ctf', 'spm', 'tal', '4d', 'yokogawa', 'neuromag', 'itab'};
- if ismember(CoregCoordsys, ViableOptions)
- cfgRealign.coordsys = CoregCoordsys;
- else
- error('Unrecognized Option.'); % error-check
- end
- % Coregister anatomy:
- cfgRealign.method = 'interactive';
- cfgRealign.parameter = 'anatomy';
- MRIdata = ft_volumerealign(cfgRealign, MRIdata);
- CheckSavePath(handles.paths.PreprocMRI{SubjIndex}, 'PreprocMRI');
- save(handles.paths.PreprocMRI{SubjIndex}, 'MRIdata');
- % Update GUI:
- handles = DetectStatus (handles, SubjIndex);
- handles = UpdateStatusSettings (handles);
- % Save handles:
- guidata(hObject, handles);
- %--- Executes on button press in ButtonCheckCoordsys. ---%
- %--------------------------------------------------------%
- function ButtonCheckCoordsys_Callback(hObject, eventdata, handles)
- if isempty(handles.name.SubjID) || isempty(handles.paths.PreprocMRI)
- msgbox('Warning: Add and select SubjID first.', 'Warning:')
- return;
- end
- % Load MRI file:
- SubjIndex = get(handles.ListboxSubjID, 'Value');
- if ~exist(handles.paths.PreprocMRI{SubjIndex}, 'file')
- msgbox('Warning: MRI file for SubjID has not been read into FT yet.', 'Warning:')
- return;
- end
- MRIdata = LoadFTmat(handles.paths.PreprocMRI{SubjIndex}, 'PreprocMRI');
- if isempty(MRIdata)
- msgbox('Error: Failed to load PreprocMRI file for SubjID. See ErrorLog.', 'Error:')
- return;
- end
- % Check coregistration:
- ft_determine_coordsys(MRIdata, 'interactive', 'no');
- %--- Executes on button press in ButtonPlotMRI. ---%
- %--------------------------------------------------%
- function ButtonPlotMRI_Callback(hObject, eventdata, handles)
- if isempty(handles.name.SubjID) || isempty(handles.paths.PreprocMRI)
- msgbox('Warning: Add and select SubjID first.', 'Warning:')
- return;
- end
- % Load MRI file:
- SubjIndex = get(handles.ListboxSubjID, 'Value');
- if ~exist(handles.paths.PreprocMRI{SubjIndex}, 'file')
- msgbox('Warning: MRI file for SubjID has not been read into FT yet.', 'Warning:')
- return;
- end
- CheckInput = CheckPipelineMat(handles.paths.PreprocMRI{SubjIndex}, 'PreprocMRI');
- if CheckInput == 0
- msgbox('Error: Failed to load PreprocMRI file for SubjID. See ErrorLog.', 'Error:')
- return;
- end
- % Plot MRI in ortho view:
- cfgPlot.method = 'ortho';
- cfgPlot.anaparameter = 'anatomy';
- cfgPlot.location = 'center';
- cfgPlot.crosshair = 'yes';
- cfgPlot.interactive = 'no';
- cfgPlot.axis = 'on';
- cfgPlot.inputfile = handles.paths.PreprocMRI{SubjIndex};
- ft_sourceplot(cfgPlot);
- %--- Executes on button press in ButtonResliceMRI. ---%
- %-----------------------------------------------------%
- function ButtonResliceMRI_Callback(hObject, eventdata, handles)
- if isempty(handles.name.SubjID) || isempty(handles.paths.PreprocMRI)
- msgbox('Warning: Add and select SubjID first.', 'Warning:')
- return;
- end
- % Check for required inputs:
- FTcfg = handles.FTcfg;
- if isempty(FTcfg.Reslice.resolution)
- msgbox('Warning: Specify resolution in physical units for resliced MRI.');
- return;
- end
- if get(handles.ButtonResliceCustomRange, 'Value') == 1
- if isempty(FTcfg.Reslice.xrange) || ...
- isempty(FTcfg.Reslice.yrange) || isempty(FTcfg.Reslice.zrange)
- msgbox('Warning: XYZ ranges not specified.');
- return;
- end
-
- XRange = str2num(get(handles.TextboxResliceXRange, 'String'));
- if ~isequal(size(XRange), [1 2]) || (XRange(1) > XRange(2))
- set(handles.TextboxResliceXRange, 'String', []);
- msgbox('Error: X-range should be: [min max] physical units.', 'Error:')
- return;
- end
-
- YRange = str2num(get(handles.TextboxResliceYRange, 'String'));
- if ~isequal(size(YRange), [1 2]) || (YRange(1) > YRange(2))
- set(handles.TextboxResliceYRange, 'String', []);
- msgbox('Error: Y-range should be: [min max] physical units.', 'Error:')
- return;
- end
-
- ZRange = str2num(get(handles.TextboxResliceZRange, 'String'));
- if ~isequal(size(ZRange), [1 2]) || (ZRange(1) > ZRange(2))
- set(handles.TextboxResliceZRange, 'String', []);
- msgbox('Error: Z-range should be: [min max] physical units.', 'Error:')
- return;
- end
- end
-
- if get(handles.ButtonResliceCustomDims, 'Value') == 1 && isempty(FTcfg.Reslice.dim)
- msgbox('Warning: Custom dimensions not specified.');
- return;
- end
- % Load selected MRI file:
- SubjIndex = get(handles.ListboxSubjID, 'Value');
- if ~exist(handles.paths.PreprocMRI{SubjIndex}, 'file')
- msgbox('Warning: MRI file for SubjID has not been read into FT yet.', 'Warning:')
- return;
- end
- MRIdata = LoadFTmat(handles.paths.PreprocMRI{SubjIndex}, 'PreprocMRI');
- if isempty(MRIdata)
- msgbox('Error: Failed to load PreprocMRI file for SubjID. See ErrorLog.', 'Error:')
- return;
- end
- % Reslice MRI:
- WaitBox = StartWaitBox('RESLICING MRI:');
- MRIdata = ft_volumereslice(FTcfg.Reslice, MRIdata);
- close(WaitBox);
- % Plot resliced MRI for user to check:
- cfgPlot.method = 'ortho';
- cfgPlot.anaparameter = 'anatomy';
- cfgPlot.location = 'center';
- cfgPlot.crosshair = 'yes';
- cfgPlot.interactive = 'no';
- cfgPlot.axis = 'on';
- ft_sourceplot(cfgPlot, MRIdata);
- % Ask user if resliced MRI should be saved:
- KeepReslice = questdlg('Keep resliced MRI or revert back to previous?', ...
- 'SAVE RESLICE?', 'KEEP', 'REVERT', 'REVERT');
- if strcmp(KeepReslice, 'KEEP')
- close(1);
- CheckSavePath(handles.paths.PreprocMRI{SubjIndex}, 'PreprocMRI');
- save(handles.paths.PreprocMRI{SubjIndex}, 'MRIdata');
- else
- close(1);
- return;
- end
- % Update GUI:
- handles = DetectStatus (handles, SubjIndex);
- handles = UpdateStatusSettings (handles);
- % Save handles:
- guidata(hObject, handles);
- %--- Executes when selected object is changed in PanelResliceMRISettings. ---%
- %----------------------------------------------------------------------------%
- function PanelResliceMRISettings_SelectionChangeFcn(hObject, eventdata, handles)
- handles = UpdatePreprocSettings(handles);
- guidata(hObject, handles);
- %--- User enters X-range for reslice here: ---%
- %---------------------------------------------%
- function TextboxResliceXRange_Callback(hObject, eventdata, handles)
- handles = UpdatePreprocSettings(handles);
- guidata(hObject, handles);
- %--- User enters Y-range for reslice here: ---%
- %---------------------------------------------%
- function TextboxResliceYRange_Callback(hObject, eventdata, handles)
- handles = UpdatePreprocSettings(handles);
- guidata(hObject, handles);
- %--- User enters Z-range for reslice here: ---%
- %---------------------------------------------%
- function TextboxResliceZRange_Callback(hObject, eventdata, handles)
- handles = UpdatePreprocSettings(handles);
- guidata(hObject, handles);
- %--- User enters custom volume dimensions for reslice here: ---%
- %--------------------------------------------------------------%
- function TextboxResliceCustomDims_Callback(hObject, eventdata, handles)
- ResliceDims = str2num(get(handles.TextboxResliceCustomDims, 'String'));
- if ~isequal(size(ResliceDims), [1 3])
- set(handles.TextboxResliceCustomDims, 'String', '256, 256, 256');
- msgbox('Error: Dim. of volume should be specified as: [nx, ny, nz].', 'Error:')
- return;
- end
- handles = UpdatePreprocSettings(handles);
- guidata(hObject, handles);
- %--- User enters resolution for reslice here (physical units): ---%
- %-----------------------------------------------------------------%
- function TextboxResliceRes_Callback(hObject, eventdata, handles)
- prompt = {'WARNING:';
- 'Are you sure you wish to change resolution of MRI?';
- 'Should not change resolution unless required.'};
- ChangeRes = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
- if strcmp(ChangeRes, 'NO')
- set(handles.TextboxResliceRes, 'String', '1');
- return;
- end
- ResliceRes = str2num(get(handles.TextboxResliceRes, 'String'));
- if ~isequal(size(ResliceRes), [1 1])
- set(handles.TextboxResliceRes, 'String', '1');
- msgbox('Error: Resolution should be single # in physical units.', 'Error:')
- return;
- end
- handles = UpdatePreprocSettings(handles);
- guidata(hObject, handles);
- %--- Updates PreprocMRI settings & GUI panel: ---%
- %------------------------------------------------%
- function OutputHandles = UpdatePreprocSettings(InputHandles)
- handles = InputHandles;
- FTcfg = handles.FTcfg;
- % Update reslice settings:
- FTcfg.Reslice = [];
- FTcfg.Reslice.resolution = str2num(get(handles.TextboxResliceRes, 'String'));
-
- if get(handles.ButtonResliceCustomDims, 'Value') == 1
- FTcfg.Reslice.dim = str2num(get(handles.TextboxResliceCustomDims, 'String'));
-
- elseif get(handles.ButtonResliceCustomRange, 'Value') == 1
- FTcfg.Reslice.xrange = str2num(get(handles.TextboxResliceXRange, 'String'));
- FTcfg.Reslice.yrange = str2num(get(handles.TextboxResliceYRange, 'String'));
- FTcfg.Reslice.zrange = str2num(get(handles.TextboxResliceZRange, 'String'));
- end
- % Enable/Disable GUI components:
- set(handles.ButtonReadMRItoFT, 'Enable', 'on');
- set(handles.ButtonClearMRI, 'Enable', 'on');
- set(handles.ButtonCheckTransformHand, 'Enable', 'on');
- set(handles.ButtonCoregisterMRI, 'Enable', 'on');
- set(handles.ButtonCheckCoordsys, 'Enable', 'on');
- set(handles.ButtonPlotMRI, 'Enable', 'on');
- set(handles.ButtonResliceMRI, 'Enable', 'on');
- set(findall(handles.PanelResliceMRISettings, '-property', 'Enable'), 'Enable', 'on');
- SubjIndex = get(handles.ListboxSubjID, 'Value');
- if isempty(handles.paths.PreprocMRI) || ~exist(handles.paths.PreprocMRI{SubjIndex}, 'file')
- set(handles.ButtonClearMRI, 'Enable', 'off');
- set(handles.ButtonCheckTransformHand, 'Enable', 'off');
- set(handles.ButtonCoregisterMRI, 'Enable', 'off');
- set(handles.ButtonCheckCoordsys, 'Enable', 'off');
- set(handles.ButtonPlotMRI, 'Enable', 'off');
- set(handles.ButtonResliceMRI, 'Enable', 'off');
- set(findall(handles.PanelResliceMRISettings, '-property', 'Enable'), 'Enable', 'off');
- end
- if get(handles.ButtonResliceDefaultDims, 'Value') == 1
- set(handles.TextboxResliceXRange, 'Enable', 'off');
- set(handles.TextboxResliceYRange, 'Enable', 'off');
- set(handles.TextboxResliceZRange, 'Enable', 'off');
- set(handles.TextboxResliceCustomDims, 'Enable', 'off');
- set(handles.TextXRange, 'Enable', 'off');
- set(handles.TextYRange, 'Enable', 'off');
- set(handles.TextZRange, 'Enable', 'off');
- set(handles.TextResliceCustomDims, 'Enable', 'off');
-
- elseif get(handles.ButtonResliceCustomDims, 'Value') == 1
- set(handles.TextboxResliceXRange, 'Enable', 'off');
- set(handles.TextboxResliceYRange, 'Enable', 'off');
- set(handles.TextboxResliceZRange, 'Enable', 'off');
- set(handles.TextXRange, 'Enable', 'off');
- set(handles.TextYRange, 'Enable', 'off');
- set(handles.TextZRange, 'Enable', 'off');
-
- elseif get(handles.ButtonResliceCustomRange, 'Value') == 1
- set(handles.TextboxResliceCustomDims, 'Enable', 'off');
- set(handles.TextResliceCustomDims, 'Enable', 'off');
-
- end
- % Set output handles:
- handles.FTcfg = FTcfg;
- OutputHandles = handles;
- %--- Reset PreprocMRI settings % GUI panel: ---%
- %----------------------------------------------%
- function OutputHandles = ResetPreprocSettings(InputHandles)
- handles = InputHandles;
- % Reset GUI reslice:
- set(handles.ButtonResliceDefaultDims, 'Value', 1);
- set(handles.TextboxResliceXRange, 'String', []);
- set(handles.TextboxResliceYRange, 'String', []);
- set(handles.TextboxResliceZRange, 'String', []);
- set(handles.TextboxResliceCustomDims, 'String', '256, 256, 256');
- set(handles.TextboxResliceRes, 'String', '1');
- % Set output handles:
- OutputHandles = handles;
- %=================================%
- % FUNCTION TO OPEN MODAL WAITBOX: %
- %=================================%
- function WaitBox = StartWaitBox(TextString)
- WaitBox = dialog('Units', 'pixels', 'Position', [500 500 300 40],...
- 'Windowstyle', 'modal', 'NextPlot', 'new', 'Name', 'Please Wait:');
- uicontrol('Parent', WaitBox, 'Units', 'pixels', 'Position', [20 10 250 20],...
- 'Style', 'text', 'String', TextString, 'FontWeight', 'bold');
- movegui(WaitBox, 'center');
- %============================%
- % GUIDE CREATEFCN FUNCTIONS: %
- %============================%
- % --- Executes during object creation, after setting all properties.
- function TextboxRootpath_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function TextboxAnatID_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function TextboxGroupID_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function ListboxSubjID_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function TextboxSubjID_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function ListboxInputAnat_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function ListboxStatus_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function DropdownCoordsys_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function TextboxResliceRes_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function TextboxResliceCustomDims_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function TextboxResliceXRange_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function TextboxResliceYRange_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- % --- Executes during object creation, after setting all properties.
- function TextboxResliceZRange_CreateFcn(hObject, eventdata, handles)
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
|